<template>
	<view class="content">
		<qiun-title-bar title="XXX统计"/>
		<!--
		极简调用示例，只需指定type及chartData即可。
		图表默认配置请修改js_sdk/u-charts/config-ucharts.js对应图表类型下配置
		注：1、更新前请自行备份config-ucharts.js、config-echarts.js，以免被覆盖
		2、此方式调用组件chartData需自行按图表类型需求的数据格式拼接
		配置参数请用在线生成工具(http://demo.ucharts.cn/)生成
		3、class="charts-box"这个样式，指定了高度，如果你的父元素有固定高度，请修改为height:100%
		-->
		<view class="charts-box">
		  <qiun-data-charts type="column" :chartData="taskAndShelfRecordData" />
		</view>

		<upgrade-center ref="upgradeCenter" theme="blue" url="/api/mobile/checkUpgrade" :autoCheck="true"></upgrade-center>
		<view style="margin-top: 80rpx;" />
	</view>
</template>

<script>
	import moment from '@/utils/moment';
	import UpgradeCenter from '@/components/upgrade-center-app/upgrade.vue';
  import { handleScan } from '@/logics/scanHandler';
	import { useScan } from "@/utils/scan-code";
	const { scan } = useScan();
	export default {
		components: {
			UpgradeCenter
		},
		data() {
			return {
				taskAndShelfRecordData: {}
			};
		},
		onShow() {
			const that = this;
			// 导航栏多语言
			uni.setNavigationBarTitle({
				title: that.$t('pages.sys.home.homeText')
			});
			// 监听扫描
			scan.start(async(res) => {
				// console.log('扫描结果', res);
        await handleScan(res);
			});
			that.refreshDashboard();
		},
		destroyed: function(){
			// uni.showModal({
			//     title: 'destroyed',
			//     content: '停止监听扫描'
			// });
			// 页面退出时一定要停止监听扫描,否则监听将一直有效
			scan.stop();
		},
    onNavigationBarButtonTap(e) {
      const that = this;
      // console.log("点击了自定义按钮", e);
      if (e.index === 0) {
        uni.scanCode({
          success: async function(res) {
            // console.log('类型', res.scanType);
            // console.log('内容', res.result);
            await handleScan({
              data: res.result
            });
          }
        });
      }
    },
		methods: {
			/** 刷新仪表盘 */
			async refreshDashboard() {
				const that = this;
				try {
					const startDate = moment().subtract(2, 'days').format("YYYY-MM-DD");
					const endDate = moment().format("YYYY-MM-DD");
					// console.log('refreshDashboard', {startDate, endDate})
					// const taskAndShelfRecordDataRes = await getTaskAndShelfRecordByDate(startDate, endDate, 'modal');
					// if (taskAndShelfRecordDataRes.Type && taskAndShelfRecordDataRes.Type === 200){
					// 	that.taskAndShelfRecordData = taskAndShelfRecordDataRes.Data;
					// }
				}
				catch(err) {}
				finally {}
			},
		}
	}
</script>

<style>
.content {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.charts-box {
  width: 100%;
  height: 200px;
}
</style>
